<template>
  <div class="warehouse-shipment-page">
    <div class="search-wrapper">
      <super-search :search-form="searchForm" :search-item-config="searchItemList" @search="searchHandle"></super-search>
    </div>
    <div class="content-wrapper">
      <a-tabs v-model:activeKey="activeKey" @change="changeTabHandle">
        <a-tab-pane key="1" :tab="`港前(${pageStat['1']})`"></a-tab-pane>
        <a-tab-pane key="2" :tab="`港后(${pageStat['2']})`"></a-tab-pane>
        <a-tab-pane key="3" :tab="`处理完成(${pageStat['3']})`"></a-tab-pane>
        <a-tab-pane key="4" :tab="`全部(${pageStat['4']})`"></a-tab-pane>
      </a-tabs>
      <super-table
        :height="tableHeight"
        ref="tableRef"
        :activeKey="activeKey"
        v-model:page="searchForm.pageNum"
        v-model:limit="searchForm.pageSize"
        :loading="loading"
        :data="tableData"
        :total="searchForm.total"
        :column="tableColumn"
        @change-page="getData"
        :sort-config="{ remote: true }"
        @sort-change="sortChangeHandle"
      >
        <template #tool>
          <a-button type="primary" @click="importBoxTransferNoHandle" v-if="['1', '2'].includes(activeKey)">更改问题类型</a-button>
          <a-button type="primary" @click="exportHandle">导出</a-button>
        </template>
        <template #workOrderNo="{ row }">
          <a-button type="link" @click="detailHandle(row)">{{ row.workOrderNo }}</a-button>
        </template>
        <template #shipmentLimit="{ row }">
          {{ row.shipmentLimit === 0 ? "否" : "是" }}
        </template>

        <template #questionScope="{ row }">
          {{ getLabelByDict("QUESTION_SCOPE", row.questionScope) }}
        </template>

        <template #questionType="{ row }">
          <span v-if="row.questionScope === 'PRE_PORT_SCOPE'" :title="getLabelByDict('PRE_PORT_SCOPE', row.questionType)"> {{ getLabelByDict("PRE_PORT_SCOPE", row.questionType) }}</span>
          <span v-if="row.questionScope === 'AFTER_PORT_SCOPE'" :title="getLabelByDict('AFTER_PORT_SCOPE', row.questionType)"> {{ getLabelByDict("AFTER_PORT_SCOPE", row.questionType) }}</span>
        </template>

        <template #action="{ row }">
          <a-button type="link" @click="detailHandle(row)" v-if="activeKey === '1'">更新进度</a-button>
          <a-button type="link" @click="detailHandle(row)" v-if="activeKey === '2'">查看进度</a-button>
        </template>
      </super-table>
    </div>

    <!-- 抽屉 -->
    <a-drawer
      class="custom-drawer"
      v-model:visible="drawerOpts.visible"
      :title="drawerOpts.title"
      :maskClosable="false"
      :closable="true"
      @close="searchHandle"
      :width="drawerOpts.width"
      placement="right"
    >
      <component
        v-model:visible="drawerOpts.visible"
        :is="drawerOpts.component"
        :type="drawerOpts.type"
        :activeKey="activeKey"
        :pass-data="drawerOpts.passData"
        @submit="drawerSubmitHandle"
      ></component>
    </a-drawer>
    <!-- 弹窗 -->
    <a-modal
      v-model:visible="dialogOpts.visible"
      :maskClosable="false"
      :keyboard="false"
      :closable="['DataStatistics'].includes(dialogOpts.component)"
      :footer="null"
      :title="dialogOpts.title"
      :width="dialogOpts.width"
    >
      <component
        v-model:visible="dialogOpts.visible"
        :is="dialogOpts.component"
        :type="dialogOpts.type"
        :pass-data="dialogOpts.passData"
        @submit="dialogSubmitHandle"
        :active-key="activeKey"
      ></component>
    </a-modal>
  </div>
</template>
<script lang="ts">
import Detail from "./components/details/index.vue";
import ModifyWorkOrderStatus from "./components/modifyWorkOrderStatus/index.vue";
import CommonHook from "@/hook/commonHook";
import TableHook from "@/hook/tableHook";
import { onActivated, onMounted } from "vue";
export default {
  name: "WorkOrder",
  components: { Detail, ModifyWorkOrderStatus }
};
</script>
<script setup lang="ts">
import TableHeightHook from "@/hook/tableHeightHook";
import { searchItemList } from "./data";
import InitHook from "./composables/initHook";
import OperationHook from "./composables/operationHook";
import ModalHook from "@/hook/modalHook";
const { tableHeight, loading } = TableHeightHook(110);
const { getLabelByDict } = CommonHook();
const { searchForm, activeKey, pageStat, tableData, tableRef, drawerOpts, tableColumn, dialogOpts } = InitHook();
const { searchHandle, changeTabHandle, getData, detailHandle, importBoxTransferNoHandle, exportHandle } = OperationHook({
  searchForm,
  tableData,
  loading,
  activeKey,
  pageStat,
  tableRef,
  drawerOpts,
  dialogOpts
});
const { sortChangeHandle } = TableHook({ searchForm }, getData);

const { drawerSubmitHandle, dialogSubmitHandle } = ModalHook({
  drawerOpts,
  dialogOpts,
  callBack: () => searchHandle()
});

onMounted(() => {
  const { waybillNums = undefined, status } = history.state;
  searchForm.workOrderNo = waybillNums;
  activeKey.value = status || "1";
  searchHandle();
});

onActivated(() => {
  const { waybillNums = undefined, status } = history.state;
  searchForm.workOrderNo = waybillNums;
  activeKey.value = status || "1";
  searchHandle();
});
</script>
<style lang="stylus" scoped>
.warehouse-shipment-page{

}
</style>
